package com.gwkj.zxjl_user.HttpUpload;

import com.upyun.library.common.UploadManager;
import com.upyun.library.listener.UpCompleteListener;
import com.upyun.library.listener.UpProgressListener;

import java.io.File;
import java.util.Map;

/**
 * Created by FuJiahui on 2016/7/6.
 */
public class UpLoadModelImpl implements UpLoadModel {

    @Override
    public void upload(UpLoadListener listener, UpLoadBean upLoadBean) {
        this.upload(listener, upLoadBean.getKey(), upLoadBean.getLocal_path(), upLoadBean.getParams(), upLoadBean.getAPIKEY());
    }

    @Override
    public void upload(final UpLoadListener listener, final int key, final String file_path, Map<String, Object> params, String apiKey) {
        UploadManager.getInstance().formUpload(new File(file_path), params, apiKey, new UpCompleteListener() {
            @Override
            public void onComplete(boolean isSuccess, String result) {
                listener.onUpLoadComplete(key, file_path, isSuccess, result);
            }
        }, new UpProgressListener() {
            @Override
            public void onRequestProgress(long bytesWrite, long contentLength) {
                listener.onUpLoadProgress(key, file_path, bytesWrite, contentLength);
            }
        });
    }
}
